-- ======================================================================
-- Hell Lua Bus
-- 
-- Copyright 2012-2013Hell-Prototypes
--
-- http://www.hellprototypes.com/
--
-- This is free software, licensed under the terms of the GNU General
-- Public License as published by the Free Software Foundation.
-- ======================================================================

hlb = require('libhlb')

function device_open()
	local ret = hlb.usb_open()
	if ret < 0 then
		print("Fail to open usb device")
		return false
	end
	
	return true
end

function device_close()
	local ret = hlb.usb_close()
	if ret < 0 then
		print("Fail to close usb device")
		return false
	end
	
	return true
end
-- -----------------------------------------------
g_8_pat = {0x08, 0x0c, 0x04, 0x06, 0x02, 0x03, 0x01, 0x09}
g_4_pat = {0x03, 0x06, 0x0c, 0x09}

g_pat = g_8_pat

if not device_open() then
	return
end

ret = hlb.port_oe(0x0f)
print("ret1 = " .. ret)
if ret < 0 then
	return
end 


for i=1, 500 do
	print("i=" .. i)
	for j=1, #g_pat do
		hlb.port_write(g_8_pat[j])
		hlb.msdelay(2)
	end
end

hlb.port_write(0x00)

ret = hlb.port_oe(0x00)
print("ret2 = " .. ret)

device_close()
